<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
  <meta charset="utf-8">
  <title>java入门精粹 &mdash; cat writebug.cn/history</title>
  <meta name="author" content="zhiliao">
  <meta name="description" content="java入门精粹" />

  <meta name="keywords" content="开发者,程序,博客园,程序猿,程序媛,极客,码农,编程,代码,软件开发,开源,IT网站,技术社区,Developer,Programmer,Coder,Geek,Coding,Code,writebug,bug,写bug,linux,vim,编程语言,调试" />

  <link href="/feeds/all.atom.xml" type="application/rss+xml" rel="alternate"
        title="cat writebug.cn/history RSS Feed" />





  <!-- http://t.co/dKP3o1e -->
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="viewport" content="width=device-width, initial-scale=1">


    <link href="/favicon.png" rel="icon">

  <link href="/theme/css/main.css" media="screen, projection"
        rel="stylesheet" type="text/css">
  <link href="/theme/css/pygment.css" rel="stylesheet" type="text/css">

  <!--
  <link href="//fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic"
        rel="stylesheet" type="text/css">
  <link href="//fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic"
        rel="stylesheet" type="text/css">
  -->


  <script src="/theme/js/modernizr-2.0.js"></script>
  <script src="/theme/js/ender.js"></script>
  <script src="/theme/js/octopress.js" type="text/javascript"></script>
</head>

<body >
  <header role="banner"
  >
<hgroup>
  <h1><a href="/">cat writebug.cn/history</a></h1>
    <h2>一个开发者的技术博客。</h2>
</hgroup></header>
  <nav role="navigation"><ul class="subscription" data-subscription="rss">
  <li><a href="/feeds/all.atom.xml" rel="subscribe-rss">RSS</a></li>
</ul>


<ul class="main-navigation">
    <li><a href="/">Home</a></li>
    <li><a href="/archives.html">Archive</a></li>
    <li><a href="/pages/todolist.html">TodoList</a></li>
    <li><a href="/pages/about.html">About</a></li>
</ul></nav>
  <div id="main">
    <div id="content">
<div>
  <article class="hentry" role="article">
<header>
      <h1 class="entry-title">java入门精粹</h1>
    <p class="meta">
<time datetime="2023-08-15T00:52:44+08:00" pubdate>2023-08-15 00:52:44</time>      
    </p>
</header>

    <div class="entry-content"><h2>第一章 java开发入门</h2>
<ol>
<li>java类只支持单继承，但接口之间支持多继承。</li>
<li>jdk包括java编译器，java运行时，java文档工具，java打包工具等。</li>
<li>jdk安装目录内的db目录，这是java实现的开源数据库javaDB,支持jdbc。</li>
<li>java源文件扩展名是.java, 编译后的字节码文件扩展名是.class。</li>
<li>HelloWrold.java</li>
</ol>
<div class="highlight-custom"><pre><span></span><code><span class="kd">class</span> <span class="nc">HelloWorld</span><span class="w"> </span><span class="p">{</span>
<span class="w">    </span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">){</span>
<span class="w">        </span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">&quot;hello world&quot;</span><span class="p">);</span>
<span class="w">    </span><span class="p">}</span>
<span class="p">}</span>
</code></pre></div>

<ol>
<li>使用javac HelloWrold.java编译。生成HelloWorld.class。javac参数是文件名。</li>
<li>java HelloWorld运行。java参数是类名。</li>
<li>java相关环境变量。PATH环境变量用来寻找java和javac等。CLASSPATH变量是java虚拟机用来加载字节码文件的路径。如果CLASSPATH没有设置，默认就是<code>.(当前目录)</code>。</li>
</ol>
<h2>第二章 java编程基础</h2>
<ol>
<li>java代码的基本格式<code>修饰符 class 类名 { 代码 }</code>。</li>
<li>java中一个字符串中间不能分在两行写， 需要分成两个字符串用<code>+</code>连接起来。</li>
<li>java中的注释包括 单行注释<code>//</code>， 多行注释<code>/*注释内容*/</code>，文档注释<code>/**注释内容*/</code>。javadoc命令用来把文档注释提取来生成帮助文档。</li>
<li>java中的标识符可以包括大小写字母，数字，下划线_，和美元符号$，不能以数字开头，且不能是java关键字。</li>
<li>建议的java命名规范</li>
</ol>
<div class="highlight-custom"><pre><span></span><code><span class="mf">1.</span><span class="w"> </span><span class="n">包名所有字母小写</span><span class="err">。</span>
<span class="mf">2.</span><span class="w"> </span><span class="n">类名和接口名每个单词首字母大写</span><span class="err">。</span>
<span class="mf">3.</span><span class="w"> </span><span class="n">常量名所有字母大写</span><span class="err">，</span><span class="n">单词间用下划线连接</span><span class="err">。</span>
<span class="mf">4.</span><span class="w"> </span><span class="n">变量名和方法名第一个单词首字母小写</span><span class="err">，</span><span class="n">从第二个单词开始首字母大写</span><span class="err">。</span>
</code></pre></div>

<ol>
<li>java关键字</li>
</ol>
<div class="highlight-custom"><pre><span></span><code><span class="n">abstract</span> <span class="n">boolean</span> <span class="k">break</span> <span class="n">byte</span> <span class="n">case</span> 
<span class="n">catch</span> <span class="n">char</span> <span class="n">const</span> <span class="k">class</span> <span class="nc">continue</span> 
<span class="n">default</span> <span class="n">do</span> <span class="n">double</span> <span class="k">else</span> <span class="n">extends</span> 
<span class="n">final</span> <span class="k">finally</span> <span class="nb">float</span> <span class="k">for</span> <span class="n">goto</span>
<span class="k">if</span> <span class="n">implements</span> <span class="kn">import</span> <span class="nn">instanceof</span> <span class="nb">int</span>
<span class="n">interface</span> <span class="n">long</span> <span class="n">native</span> <span class="n">new</span> <span class="n">package</span>
<span class="n">private</span> <span class="n">protected</span> <span class="n">public</span> <span class="k">return</span> <span class="n">short</span>
<span class="n">static</span> <span class="n">strictfp</span> <span class="nb">super</span> <span class="n">switch</span> <span class="n">this</span>
<span class="n">throw</span> <span class="n">throws</span> <span class="n">transient</span> <span class="k">try</span> <span class="n">void</span>
<span class="n">volatile</span> <span class="k">while</span> <span class="n">synchronized</span>
<span class="n">所有关键字都是小写的</span>
</code></pre></div>

<ol>
<li>java中的整形常量支持二进制八进制十进制十六进制表示，二进制八进制十六进制分别以<code>0b/0B，0, 0x/0X</code>开头。</li>
<li>java浮点型常量，单精度后面用F/f结尾，双精度后面用D/d结尾。d可以不写，默认是双精度。</li>
<li>java字符常量，要用英文单引号引起来，java使用unicode字符集，支持转义字符，支持 '\u0000'。</li>
<li>java布尔常量包括true 和false。</li>
<li>null类型常量只有一个值null,表示对象的引用是空。</li>
<li>十进制转二进制是一个不断除以2区余数的过程。把要转换的数除以2,得到商和余数，把商继续除以2,直到商为0.</li>
<li>二进制转十进制要从右到左用二进制位上的每个数乘以2的相应次方。</li>
<li>java是强类型的语言。数据类型分成基本数据类型和引用数据类型。基本数据类型包括数值型（byte short int long float double）和字符型char，布尔型boolean。引用数据类型包括类class, 接口interface,数组，枚举enum,注解annotation。</li>
<li>占用空间，（单位字节）byte类型 1，short 2, int 4, long 8. </li>
<li>long型变量赋值时候右面的常量需要用L结尾。</li>
<li>char类型变量占用2个字节。也可以把char赋值为0-65535之间的整数。</li>
<li>boolean类型变量取值是true或false。</li>
<li>强制类型转换<code>目标类型 变量 = (目标类型)值</code></li>
<li>变量在表达式中进行运算时，可能会发生自动类型转换，比如byte自动转换为int.</li>
<li>java中的算术运算符包括<code>+（正号） -（负号）+ - * / % ++（前） ++（后）--（前）--（后）</code>。</li>
<li>在进行除法运算时，当除数和被除数都是整数时，得到的结果也是整数，如果除法运算有小数参与，得到的结果是小数。</li>
<li>在进行取模运算时，运算结果的正负取决于被模数（左边的数）的负号，与模数（右边的数）的符号无关。</li>
<li>赋值运算符包括<code>= += -= *= /= %=</code>。赋值运算符是有返回值的，可以用一条语句为多个变量赋值，比如<code>a=b=c=5;</code></li>
<li>用=为变量赋值时，在目标类型取值范围小于源类型时，比如将int变量赋值给short类型变量，需要显示的强制类型转换。用<code>+= -= *= /= %=</code>为变量赋值时，强制类型转换会自动完成。</li>
<li>比较运算符包括<code>== != &lt; &gt; &lt;= &gt;=</code>。</li>
<li>逻辑运算符用于对布尔类型的数据运算，结果也是布尔类型数据。包括<code>&amp;  |  ^异或  !非  &amp;&amp;  ||</code>。</li>
<li>&amp;&amp;是短路与，&amp;不短路。||是短路或，|不短路。</li>
<li><code>^</code>表示异或。</li>
<li>位运算符包括<code>&amp;按位与  |按位或  ~去反  ^按位异或  &lt;&lt;左移  &gt;&gt;右移  &gt;&gt;&gt;无符号右移</code></li>
<li>运算符优先级，<code>. []  ()</code>优先级最高，赋值运算符优先级最低。</li>
<li>选择结构语句支持<code>if(){}else{}</code>，和C一样。支持<code>判断条件?表达式1:表达式2</code>三元运算符。</li>
<li>switch语句用法和C里面一样，但支持了String。</li>
<li>while,do...while,for,break,continue用法和C中一样，但break和continue额外支持标记，多层循环时，用来跳出外层循环。用法是</li>
</ol>
<div class="highlight-custom"><pre><span></span><code><span class="n">itcast</span><span class="o">:</span><span class="w"> </span><span class="k">for</span><span class="o">(</span><span class="n">i</span><span class="o">=</span><span class="mi">0</span><span class="o">;</span><span class="w"> </span><span class="n">i</span><span class="o">&lt;</span><span class="mi">10</span><span class="o">;</span><span class="w"> </span><span class="n">i</span><span class="o">++){</span>
<span class="w">    </span><span class="k">for</span><span class="o">(</span><span class="n">j</span><span class="o">=</span><span class="mi">0</span><span class="o">;</span><span class="w"> </span><span class="n">j</span><span class="o">&lt;</span><span class="mi">10</span><span class="o">;</span><span class="w"> </span><span class="n">j</span><span class="o">++){</span>
<span class="w">        </span><span class="o">...</span>
<span class="w">        </span><span class="k">break</span><span class="w"> </span><span class="n">itcast</span><span class="o">;</span><span class="w"> </span><span class="c1">//跳出外层循环</span>
<span class="w">    </span><span class="o">}</span>
<span class="o">}</span>
</code></pre></div>

<ol>
<li></li>
</ol>
<p>已经读完了page58/426。
后面的内容有机会补充</p></div>
    <footer>
<p class="meta">
  <span class="byline author vcard">
    Posted by <span class="fn">
        zhiliao
    </span>
  </span>
<time datetime="2023-08-15T00:52:44+08:00" pubdate>2023-08-15 00:52:44</time>  <span class="categories">
    <a class='category' href='/category/programming.html'>programming</a>
  </span>
  <span class="categories">
    <a class="category" href="/tag/programming-language.html">programming-language</a>,    <a class="category" href="/tag/java.html">java</a>  </span>
</p><div class="sharing">
</div>    </footer>
  </article>

</div>

<aside class="sidebar">
<section>
  <h1>Recent Posts</h1>
  <ul id="recent_posts">
    <li class="post">
        <a href="/posts/2023/08/22/bash-conversion.html">bash进制转换</a>
    </li>
    <li class="post">
        <a href="/posts/2023/08/16/remap-caps-ctrl.html">在Linux下交换Ctrl与大写锁定键</a>
    </li>
    <li class="post">
        <a href="/posts/2023/08/15/learn-java.html">java入门精粹</a>
    </li>
    <li class="post">
        <a href="/posts/2023/08/04/tcl-expect.html">Tcl 和 expect教程</a>
    </li>
    <li class="post">
        <a href="/posts/2023/08/01/armbian-config-software.html">armbian-config 支持自动安装的软件</a>
    </li>
  </ul>
</section><section>
  <h1>Categories</h1>
    <ul id="recent_posts">
      <li><a href="/category/android.html">android (2)</a></li>
      <li><a href="/category/blog.html">blog (1)</a></li>
      <li><a href="/category/bootloader.html">bootloader (2)</a></li>
      <li><a href="/category/container.html">container (1)</a></li>
      <li><a href="/category/database.html">database (1)</a></li>
      <li><a href="/category/editor.html">editor (4)</a></li>
      <li><a href="/category/filesystem.html">filesystem (1)</a></li>
      <li><a href="/category/firefox.html">firefox (1)</a></li>
      <li><a href="/category/git.html">git (4)</a></li>
      <li><a href="/category/golang.html">golang (1)</a></li>
      <li><a href="/category/gu-piao.html">股票 (1)</a></li>
      <li><a href="/category/ide.html">IDE (1)</a></li>
      <li><a href="/category/interview.html">interview (1)</a></li>
      <li><a href="/category/linux.html">linux (51)</a></li>
      <li><a href="/category/network.html">network (7)</a></li>
      <li><a href="/category/nltk.html">nltk (2)</a></li>
      <li><a href="/category/notes.html">notes (1)</a></li>
      <li><a href="/category/other.html">other (1)</a></li>
      <li><a href="/category/programming.html">programming (10)</a></li>
      <li><a href="/category/python.html">python (1)</a></li>
      <li><a href="/category/software.html">software (1)</a></li>
      <li><a href="/category/stock.html">stock (1)</a></li>
      <li><a href="/category/storage.html">storage (2)</a></li>
      <li><a href="/category/vm.html">vm (1)</a></li>
      <li><a href="/category/web.html">web (4)</a></li>
      <li><a href="/category/windows.html">windows (1)</a></li>
      <li><a href="/category/xwindow.html">xwindow (1)</a></li>
  </ul>
</section>
<section>
  <h1>Tags</h1>
    <a href="/tag/linux.html">linux</a>,    <a href="/tag/bash.html">bash</a>,    <a href="/tag/xwindow.html">Xwindow</a>,    <a href="/tag/programming-language.html">programming-language</a>,    <a href="/tag/java.html">java</a>,    <a href="/tag/programming.html">programming</a>,    <a href="/tag/software.html">software</a>,    <a href="/tag/storage.html">storage</a>,    <a href="/tag/debug.html">debug</a>,    <a href="/tag/c.html">C</a>,    <a href="/tag/git.html">git</a>,    <a href="/tag/patch.html">patch</a>,    <a href="/tag/text.html">text</a>,    <a href="/tag/selenium.html">selenium</a>,    <a href="/tag/web.html">web</a>,    <a href="/tag/docker.html">docker</a>,    <a href="/tag/flatpak.html">flatpak</a>,    <a href="/tag/interview.html">interview</a>,    <a href="/tag/qt.html">Qt</a>,    <a href="/tag/opensuse.html">openSUSE</a>,    <a href="/tag/filesystem.html">filesystem</a>,    <a href="/tag/ide.html">IDE</a>,    <a href="/tag/glang.html">glang</a>,    <a href="/tag/xdg.html">xdg</a>,    <a href="/tag/network.html">network</a>,    <a href="/tag/raspberry.html">raspberry</a>,    <a href="/tag/vm.html">vm</a>,    <a href="/tag/windows.html">windows</a>,    <a href="/tag/gdb.html">gdb</a>,    <a href="/tag/debian.html">debian</a>,    <a href="/tag/archlinux.html">archlinux</a>,    <a href="/tag/phicomm.html">phicomm</a>,    <a href="/tag/kernel.html">kernel</a>,    <a href="/tag/ext4.html">ext4</a>,    <a href="/tag/server.html">server</a>,    <a href="/tag/stock.html">stock</a>,    <a href="/tag/shu.html">书</a>,    <a href="/tag/gu-piao.html">股票</a>,    <a href="/tag/python.html">python</a>,    <a href="/tag/nltk.html">nltk</a>,    <a href="/tag/command.html">command</a>,    <a href="/tag/shell.html">shell</a>,    <a href="/tag/terminal.html">terminal</a>,    <a href="/tag/other.html">other</a>,    <a href="/tag/wireless.html">wireless</a>,    <a href="/tag/android.html">android</a>,    <a href="/tag/gtk.html">gtk+</a>,    <a href="/tag/gnome.html">gnome</a>,    <a href="/tag/keyboard.html">keyboard</a>,    <a href="/tag/firefox.html">firefox</a>,    <a href="/tag/arch.html">arch</a>,    <a href="/tag/database.html">database</a>,    <a href="/tag/mysql.html">mysql</a>,    <a href="/tag/notes.html">notes</a>,    <a href="/tag/sysctl.html">sysctl</a>,    <a href="/tag/vim.html">vim</a>,    <a href="/tag/editor.html">editor</a>,    <a href="/tag/pelican.html">pelican</a>,    <a href="/tag/blog.html">blog</a>,    <a href="/tag/book.html">book</a>,    <a href="/tag/bootloader.html">bootloader</a></section>
    <section>
        <h1>Social</h1>
        <ul>
            <li><a href="https://github.com/zhangjiaxing" target="_blank">github</a></li>
            <li><a href="http://wpa.qq.com/msgrd?v=3&uin=347820393&site=qq&menu=yes" target="_blank">qq</a></li>
            <li><a href="http://www.writebug.cn" target="_blank">blog</a></li>
            <li><a href="http://gallery.writebug.cn" target="_blank">gallery</a></li>
        </ul>
    </section>
    <section>
        <h1>Blogroll</h1>
        <ul>
            <li><a href="http://getpelican.com/" target="_blank">Pelican</a></li>
        </ul>
    </section>

</aside>
    </div>
  </div>
  <footer role="contentinfo">
<p>
    Copyright &copy;  2013&ndash;2023  zhiliao &mdash;
  <span class="credit">Powered by <a href="http://getpelican.com">Pelican</a></span>
</p>  </footer>
</body>
</html>